(:
   Conversion of a display file to Excel XML format
 :)
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;
declare namespace ss = "http://example.org";

let $doc := doc($arguments[1])
let $il := $doc//item
let $infocount := for $item in $il return count($item/info)
    
return
<Workbook
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:html="http://www.w3.org/TR/REC-html40"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
>
<Worksheet ss:Name="DREW">
<Table ss:ExpandedColumnCount="{max($infocount)}" ss:ExpandedRowCount="{count($il)}" 
   x:FullColumns="1" x:FullRows="1"
  >
   <Column ss:Index="2" ss:AutoFitWidth="0" ss:Width="150.0"/>
   <Column ss:Index="5" ss:AutoFitWidth="0" ss:Width="250.0"/>
   <Column ss:Index="6" ss:AutoFitWidth="0" ss:Width="150.0"/>
   {
   for $e in $il
   return
      (<Row>
        {
  if ($e/info[@name="time"]) then <Cell><Data ss:Type="String">{jj:dateFromDREW($e/info[@name="time"]/time/date)}</Data></Cell>
  else (),
	for $info in $e/info[not(@name = ("src-anchor","time","begin","end"))]
	return
        <Cell><Data ss:Type="String">{string($info)}</Data></Cell>
        }
      </Row>)
   }
</Table>
</Worksheet>
</Workbook>
